package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	fileName := "advance/fileIO/testFiles/test02.txt"
	/*file, _ := os.OpenFile(fileName, os.O_WRONLY, 0666)*/
	file, _ := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY, 0666)
	reader := bufio.NewReader(file)
	for {
		content, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		fmt.Print(content)
	}

	str := "hello BeiJing\n"
	writer := bufio.NewWriter(file)
	for i := 0; i < 10; i++ {
		_, _ = writer.WriteString(str)
	}
	writer.Flush()
	file.Close()
}
